// IPConfigDialog.cpp : implementation file
//

#include "stdafx.h"
#include "GPSwSmartPhone.h"
#include "IPConfigDialog.h"


// IPConfigDialog dialog

IMPLEMENT_DYNAMIC(IPConfigDialog, CDialog)

IPConfigDialog::IPConfigDialog(CWnd* pParent /*=NULL*/)
	: CDialog(IPConfigDialog::IDD, pParent)
{

}

IPConfigDialog::~IPConfigDialog()
{
}

void IPConfigDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_IP_ADDRESS, IPAddressBox);
	DDX_Control(pDX, IDC_PORT_BOX, portBox);
}


BEGIN_MESSAGE_MAP(IPConfigDialog, CDialog)
	ON_BN_CLICKED(IDC_BUTTON1, &IPConfigDialog::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &IPConfigDialog::OnBnClickedButton2)
END_MESSAGE_MAP()

// IPConfigDialog message handlers

//"OK" button
void IPConfigDialog::OnBnClickedButton2()
{
	OnOK();
}

void IPConfigDialog::OnOK()
{
	if(gps)
	{
	//Commit IP options changes
	LPTSTR ip = new wchar_t[20];
	LPTSTR port = new wchar_t[20];
	gps->setIPAddress((LPCTSTR)IPAddressBox.GetLine(0, ip, 15));
	u_short portNr = atoi((char *)portBox.GetLine(0, port));
	gps->setTCPPort(portNr);
	}
}

//"Cancel" button
void IPConfigDialog::OnBnClickedButton1()
{
	// TODO: Add your control notification handler code here
	this->DestroyWindow();
}

void IPConfigDialog::setCommsObject(GPScomm *c)
{
	gps = c;
}